home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.9 KB | 351 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ClipCmds.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef CLIPCMDS_H
- #include "ClipCmds.h"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- // ----- FrameWork Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawcommand
- #endif
-
- FW_DEFINE_AUTO(CDrawClipboardCommand)
-
- //========================================================================================
- // CDrawClipboardCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand constructor
- //----------------------------------------------------------------------------------------
-
- CDrawClipboardCommand::CDrawClipboardCommand(Environment* ev,
- ODCommandID commandID,
- CDrawPart* part,
- CDrawFrame* frame,
- CDrawSelection* selection,
- FW_Boolean canUndo) :
- FW_CClipboardCommand(ev, commandID, frame, canUndo),
- fDrawPart(part),
- fDrawSelection(selection),
- fUndoContent(NULL),
- fSavedLink(NULL),
- fLinkSources(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand destructor
- //----------------------------------------------------------------------------------------
-
- CDrawClipboardCommand::~CDrawClipboardCommand()
- {
- FW_START_DESTRUCTOR
- delete fUndoContent;
- delete fLinkSources;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::SaveUndoState(Environment* ev) // Override
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandCut || commandID == kODCommandClear)
- {
- FW_ASSERT(fUndoContent == NULL);
- fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawPart, fDrawSelection));
-
- // Obtain a list of links sources to update before removing anything!
- // This will do for now, but doesn't filter out any sources
- // which will be removed in their entirety, so needn't be updated.
-
- fLinkSources = fDrawSelection->GetSelectedLinkSources();
-
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::SaveRedoState(Environment* ev) // Override
- {
- if (this->IsPasteWithoutLink(ev))
- {
- FW_ASSERT(fUndoContent == NULL);
- fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawPart, fDrawSelection));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::FreeUndoState(Environment* ev) // Override
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandCut || commandID == kODCommandClear)
- {
- // Delete link sources left empty because all their shapes were removed
- fUndoContent->DeleteEmptyLinkSources(ev);
-
- // Delete undo data
- fUndoContent->DeleteSavedShapesAndLinks(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::FreeRedoState(Environment* ev) // Override
- {
- if (this->IsPasteWithoutLink(ev))
- fUndoContent->DeleteSavedShapes(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::UndoIt(Environment* ev) // Override
- {
- FW_CClipboardCommand::UndoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- fUndoContent->RestoreShapeSelection(ev);
- fUndoContent->RestoreLinks(ev);
- break;
-
- case kODCommandPasteAs:
- if (fSavedLink)
- {
- fSavedLink->SelectShapes(ev); // set the selection's update shape
- GetDrawLinkManager(ev)->UndoPasteAs(ev, fSavedLink);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- break;
- }
- // else fall through to kODCommandPaste
-
- case kODCommandPaste:
- fUndoContent->RemoveShapeSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::RedoIt(Environment* ev) // Override
- {
- FW_CClipboardCommand::RedoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- fUndoContent->RemoveShapeSelection(ev);
- fUndoContent->RemoveFromLinks(ev);
- break;
-
- case kODCommandPasteAs:
- if (fSavedLink)
- {
- GetDrawLinkManager(ev)->RedoPasteAs(ev, fSavedLink);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- break;
- }
- // else fall through to kODCommandPaste
-
- case kODCommandPaste:
- fUndoContent->RestoreShapeSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::PreCommand
- //----------------------------------------------------------------------------------------
-
- void CDrawClipboardCommand::PreCommand(Environment* ev)
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandPaste || commandID == kODCommandPasteAs)
- fDrawSelection->CloseSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::CommandDone
- //----------------------------------------------------------------------------------------
-
- void CDrawClipboardCommand::CommandDone(Environment* ev)
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandPaste)
- fDrawSelection->CenterSelection(ev, GetFrame(ev));
- else if (commandID == kODCommandPasteAs)
- {
- fSavedLink = (CDrawSubscribeLink*)GetNewLink(ev);
- if (fSavedLink && fSavedLink->IsEstablished(ev)) // cross-doc link not yet established
- {
- // Select the newly-subscribed shapes
- fSavedLink->SelectShapes(ev);
-
- // Offset the selection, saving the offset for later updates
- FW_CPoint offset = fDrawSelection->CenterSelection(ev, GetFrame(ev));
-
- // Save information about newly-created link
- fSavedLink->SetUpdateOffset(ev, offset);
- }
- }
- else if (commandID == kODCommandCut || commandID == kODCommandClear)
- {
- fUndoContent->RemoveFromLinks(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::IsPasteWithoutLink
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawClipboardCommand::IsPasteWithoutLink(Environment* ev) const
- {
- if (GetCommandID(ev) == kODCommandPaste)
- return TRUE;
- if (GetCommandID(ev) == kODCommandPasteAs)
- return (fSavedLink == NULL);
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::GetDrawLinkManager
- //----------------------------------------------------------------------------------------
-
- CDrawLinkManager* CDrawClipboardCommand::GetDrawLinkManager(Environment* ev) const
- {
- return (CDrawLinkManager*)GetPart(ev)->GetLinkManager(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::CommitUndone
- //----------------------------------------------------------------------------------------
-
-
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::CommitDone
- //----------------------------------------------------------------------------------------
-
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::PropagateChanges
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::PropagateChanges(Environment* ev, ODUpdateID id )
- {
- if (fLinkSources)
- {
- //--- Update affected links ---
- id = FW_CSession::UniqueUpdateID(ev);
- CDrawPublishLinkCollectionIterator iter(fLinkSources);
- for (CDrawPublishLink* link = iter.First(); iter.IsNotComplete(); link = iter.Next())
- {
- link->ContentUpdated(ev, id);
- }
- }
-
- FW_CClipboardCommand::PropagateChanges(ev, id);
- }
-
-
-
-